package com.veeva;

import java.util.Scanner;

public class DayOfYear {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Please input year:");
        int year = input.nextInt();
        System.out.println("Please input month:");
        int month = input.nextInt();
        System.out.println("Please input day:");
        int day = input.nextInt();
        System.out.println(dayOfYear(year, month, day));
    }

    private static int dayOfYear(int year, int month, int day) {
        if (year < 1970 || month < 1 || month > 12) {
            return -1;
        }
        // The number of days in a month
        int[] daysInMonth = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        // Determines whether the year is a leap year
        boolean isLeapYear = ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) ? true : false;
        if (isLeapYear) {
            ++daysInMonth[1];
        }
        if (day < 1 || day > daysInMonth[month - 1]) {
            return -1;
        }
        int days = 0;
        for (int i = 1; i < month; i++) {
            days += daysInMonth[i - 1];
        }
        days += day;
        return days;
    }

}
